﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class EmailSendEventHandler : IIntegrationEventHandler<EmailSendEvent>
    {
        private readonly IEmailService _emailService;//假设IEmailService是发送邮件的服务
        public EmailSendEventHandler(IEmailService emailService)
        {
            _emailService = emailService;
        }

        public async Task Handle(EmailSendEvent @event)
        {
            var tasks = new List<Task>();
            tasks.Add(Task.Run(async () =>
            {
                //这里调用邮件服务发送邮件
                _emailService.SendEmailAsync(@event.Receiver, @event.EmailSubject, @event.EmailBody);
            }));

            await Task.WhenAll(tasks);
            Console.WriteLine($"Emailsentto{@event.Receiver}");
        }
    }
}
